package com.cskaoyan.gateway.controller.shopping;

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.shopping.IContentService;
import com.mall.shopping.IHomeService;
import com.mall.shopping.IProductCateService;
import com.mall.shopping.dto.HomePageResponse;
import com.mall.shopping.dto.NavListResponse;
import com.mall.user.annotation.Anoymous;
import com.mall.user.constants.SysRetCodeConstants;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("shopping")
@Anoymous
public class HomepageController {

    @Reference(check = false)
    private IHomeService iHomeService;

    @Reference(check = false)
    IHomeService homeService;

    @Reference(check = false, timeout = 1000, retries = 0)
    IContentService contentService;

    @Reference(check = false, timeout = 1000, retries = 0)
    IProductCateService productCateService;

    @GetMapping("homepage")
    public ResponseData homepage(){
        HomePageResponse response = iHomeService.homepage();
        if (SysRetCodeConstants.SUCCESS.getCode().equals(response.getCode())) {
            return new ResponseUtil().setData(response.getPanelContentItemDtos());
        }
        return new ResponseUtil().setErrorMsg(
                Integer.parseInt(response.getCode()), response.getMsg());

    }

    @GetMapping("navigation")
    public ResponseData showNavigation() {
        NavListResponse response = contentService.queryNavList();
        if (SysRetCodeConstants.SUCCESS.getCode().equals(response.getCode())) {
            return new ResponseUtil().setData(response.getPannelContentDtos());
        }
        return new ResponseUtil().setErrorMsg(
                Integer.parseInt(response.getCode()), response.getMsg());
    }

}
